
/*
* @version: 1.0
* @Author: zhanggq
* @Date: 2023-08-07 19:01:00
* @LastEditTime: 2023-08-07 16:39:30
* @Description: 沧州项目补丁，注册模型增加DevID和CollectTime两个字段，数据上报时向两个字段赋值
*/

#ifndef   __CANGZHOU_RPT_PATHCH__
#define   __CANGZHOU_RPT_PATHCH__

#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <unordered_map>

#include "../../../include/protocol_engine_config.h"
#include "../../../include/DCData.h"
#include "../../common/include/common.h"
#include "../../common/include/CConfigManager.h"

class CCangZhouRptPatch
{
public:
    CCangZhouRptPatch();
    ~CCangZhouRptPatch();

    static CCangZhouRptPatch* getInstance();

    void AppendModelItem(std::list<ST_MODEL_PTINFO>& lstModelPts){
        if (0 ==lstModelPts.size()) {
            return; //原模型列表为空，不处理
        }
        ST_MODEL_PTINFO  stModelPt;
        stModelPt.name = "DevID";
        stModelPt.ratio = "1";
        stModelPt.type = "string";
        stModelPt.unit = " ";
        stModelPt.isreport = "1";
        stModelPt.deadzone = "0";
        stModelPt.userdefine = "";
        lstModelPts.push_back(stModelPt);

        stModelPt.name = "CollectTime";
        lstModelPts.push_back(stModelPt);
    }

    void AppendRptItem(std::shared_ptr<CConfigManager>  cm, int64_t dev_id, std::list<ST_REPORT_DATAPT>& lstReportPts){
        if ((nullptr== cm) || (0 ==lstReportPts.size())) {
            return;
        }

        auto dev = cm->get_terminal_device(dev_id);
        if (nullptr ==dev) {
            return;
        }
        ST_REPORT_DATAPT  stReportPt;
        stReportPt.name = "DevID";
        stReportPt.val = dev->node_id;
        stReportPt.quality = "0";
        get_uart_timestamp(stReportPt.timestamp);
        lstReportPts.push_back(stReportPt);

        stReportPt.name = "CollectTime";
        get_uart_timestamp(stReportPt.timestamp);
        stReportPt.val = stReportPt.timestamp;
        stReportPt.quality = "0";
        
        lstReportPts.push_back(stReportPt);
    }

private:
    static CCangZhouRptPatch  c_CangzhouRptPatch;

};

#endif

CCangZhouRptPatch   CCangZhouRptPatch::c_CangzhouRptPatch;
CCangZhouRptPatch::CCangZhouRptPatch()
{
}

CCangZhouRptPatch::~CCangZhouRptPatch()
{
}

CCangZhouRptPatch* CCangZhouRptPatch::getInstance()
{
    return &c_CangzhouRptPatch;
}
